<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>{$setting.webname} - 修改管理员</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/public/static/admin/layui/css/layui.css" rel="stylesheet">
    <link rel="shortcut icon" href="/public/static/favicon.ico">
    <link href="/public/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/public/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="/public/static/admin/css/animate.css" rel="stylesheet">
    <link href="/public/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/public/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <style>
        .menuTitle{
            margin-top:10px;
            line-height: 35px;
            background:#f5f5f5;
            color:#000;
            padding-left:15px;
            border-radius: 3px;
        }
    </style>


</head>

<body class="gray-bg">
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <h2>修改管理员</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="{:url('Admins/admin')}">主页</a>
                </li>
                <li>
                    <strong>修改管理员</strong>
                </li>
            </ol>
        </div>
    </div>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
             <div class="col-sm-12">
			 
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编辑管理员信息</h5>
					</div>
                    <div class="ibox-content">
                        <form class="form-horizontal">
						    
                           <div class="form-group">
                                <label class="col-sm-2 control-label">用户名：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入用户名" id="username" value="{$data.username}" class="form-control">
                                </div>
								<div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">密码：</label>
                                <div class="col-sm-4">
                                    <input type="password" placeholder="请输入密码" id="password" class="form-control"/>
                                </div>
                                <div class="col-sm-6">(*如果不修改密码只需要留空即可)</div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">确认密码：</label>
                                <div class="col-sm-4">
                                    <input type="password" placeholder="请再次输入密码" id="password2" class="form-control">
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">手机号码：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入手机号码" value="{$data.phone}" id="phone" class="form-control">
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">邮箱：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入邮箱地址" value="{$data.email}" id="email" class="form-control">
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">联系地址：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入联系地址" value="{$data.map}" id="map" class="form-control">
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">职务：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入联系职务" value="{$data.post}" id="post" class="form-control">
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">状态：</label>
                                <div class="col-sm-4">
                                    <div class="radio i-checks">
                                        <label><input type="radio" name="status" value="1" class="status" checked>  可用</label>
                                        <label><input type="radio" name="status" value="2" class="status">  不可用</label>
                                    </div>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">选择栏目权限：</label>
                                <div class="col-sm-4">
                                    {foreach $menu as $key=>$vo}
                                    <div class="menuTitle">{$vo.title}<input type="checkbox" id="parmenu{$key}" style="display: none" value="{$vo.id}"></div>
                                    <div class="checkbox i-checks">
                                        {foreach $vo.tow as $k=>$vs}
                                        <label><input type="checkbox" value="{$vs.id}" class="menu{$key}" pid="{$key}"> {$vs.title} </label>
                                        {/foreach}
                                    </div>
                                    {/foreach}

                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-4">
                                    (被选择的栏目可以在该用户后台显示)
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!-- 上传图片 -->
                          <div class="form-group">
                            <label class="col-sm-2 control-label">头像（本地上传）：</label>
                            <div class="col-sm-6">
                              <input type="button" class="btn btn-success" value="已上传的图片" id="selffile">
                              <button type="button" class="btn btn-info" id="test1">上传图片</button>
                              <div class="layui-upload-list">
                                <img class="layui-upload-img" id="demo1" src="{$data.photo}">
                                <p id="demoText"></p>
                              </div>
                            </div>
                            <div class='col-sm-4'></div>
                          </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-9">
                                    <button class="btn btn-sm btn-info" type="button" id="adds">保 存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
		</div>
	</div>
    <style>
      .layer_notive{
        width: 700px;
        margin: 20px auto;
        min-height: 500px;
        display: none;
      }
      .layer_notive ul li{
        float:left;
        margin:5px;
        width: 220px;

      }
      .layer_notive ul li img{
        max-width: 100%;
        padding:1px;
        border:2px solid #ccc;
        opacity: 0.7;
      }
      .active{
        border:2px solid green!important;
        opacity: 1!important;
      }
    </style>
    <!--弹出已上传的图片-->
    <div class="layer_notive" >
      <ul id="imglist"></ul>
      <div style="clear:both"></div>
    </div>
    <!-- 全局js -->
    <script src="/public/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/static/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="/public/static/admin/js/content.js?v=1.0.0"></script>
    <script src="/public/static/admin/js/jquery.min.js"></script>
    <script src="/public/static/admin/layui/layui.js"></script>
    <!--icheck-->
    <script src="/public/static/admin/js/plugins/iCheck/icheck.min.js"></script>

    <script>
        /*
         * 状态默认选中
         */
        $("input:radio[value='{$data.status}']").iCheck('check');
        {foreach $data['jurisdiction'] as $k=>$vo}
           $("input:checkbox[value='{$vo}']").iCheck('check');
        {/foreach}
        /*
         * icheck
         */
        $('input[class^="menu"]').on('ifChanged', function(event){
            var className = $(this).attr("class");
            var pid = $(this).attr("pid");
            var menu = $(".menu"+pid);
            var preObj = $("#parmenu"+pid);
            var s = 0;
            for(i in menu){
                if(menu.eq(i).is(":checked")){
                    s++;
                }
            }
            if(s === 0){
                preObj.prop("checked",false);
            }else if(s >0){
                preObj.prop("checked",true);
            }
        });

        //单选和复选框
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
        //layui
        layui.use('upload', function(){ //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer,upload=layui.upload;//独立版的layer无需执行这一句

            var photo ="{$data.photo}";
            //点击提交
            $("#adds").click(function(){
                //获取所有导航复选框
                var jurisdiction = $("input:checkbox");
                //创建新的字符串
                var jur = "";
                //循环判断哪些是被选中的，并将vale保存在新字符串jur中
                for(i=0;i<jurisdiction.length;i++){
                    if(jurisdiction.eq(i).is(":checked")) {
                        jur += jurisdiction.eq(i).val() + ",";
                    }
                }
                //获取状态
                var status = $("input:radio[class='status']");
                var statusVal  = "";
                for(i in status){
                    if(status.eq(i).is(":checked")) {
                        var statusVal =status.eq(i).val();
                    }
                }
                if($("#username").val() == ""){
                    top.layer.msg("请输入用户名");
                }else{
                    //判断两次密码是否一致
                    if($("#password").val() == $("#password2").val()){
                        //判断电话号码是否为空
                        if($("#phone").val() == ""){
                            top.layer.msg("请输入电话号码");
                        }else{
                            //判断是否是手机号码格式
                            var phonepreg = /^1(3|5|7|8|9)\d{9}$/;
                            if(!phonepreg.test($("#phone").val())){
                                top.layer.msg("请输入正确手机号码");
                            }else{
                                //判断邮箱是否为空
                                if($("#email").val() == ""){
                                    top.layer.msg("请输入邮箱");
                                }else{
                                    //判断邮箱是邮箱格式
                                    var emailPreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                                    if(emailPreg.test($("#email").val())) {
                                        if ($("#map").val() == "") {
                                            top.layer.msg("请输入联系地址");
                                        } else {
                                           //判断密码是否修改
                                           if($("#password").val() != "") {
                                               //提交ajax添加用户
                                               $.post("{:url('Admins/toupdate')}", {
                                                   id:{$data.id},
                                                   username: $("#username").val(),
                                                   password: $("#password").val(),
                                                   status: statusVal,
                                                   phone: $("#phone").val(),
                                                   email: $("#email").val(),
                                                   post: $("#post").val(),
                                                   photo: photo,
                                                   map: $("#map").val(),
                                                   jurisdiction: jur
                                               }, function (data) {
                                                   top.layer.msg(data.msg, {time: 2000,shade:0.5}, function () {
                                                       if (data.url) {
                                                         if({$isSelf}==1) parent.location.reload();
                                                           window.location.href = data.url;
                                                       }
                                                   });
                                               });
                                           }else{
                                               //提交ajax添加用户
                                               $.post("{:url('Admins/toupdate')}", {
                                                   id:{$data.id},
                                                   username: $("#username").val(),
                                                   status: statusVal,
                                                   phone: $("#phone").val(),
                                                   email: $("#email").val(),
                                                   map: $("#map").val(),
                                                   post: $("#post").val(),
                                                   photo: photo,
                                                   jurisdiction: jur
                                               }, function (data) {
                                                   top.layer.msg(data.msg, {time: 2000,shade:0.5}, function () {
                                                       if (data.url) {
                                                         if({$isSelf}==1) parent.location.reload();
                                                           window.location.href = data.url;
                                                       }
                                                   });
                                               });
                                           }
                                        }
                                    }else{
                                        top.layer.msg("请输入正确邮箱");
                                    }
                                }
                            }
                        }
                    }
                }

            });
          //普通图片上传
          var uploadInst = upload.render({
            elem: '#test1'
            ,url: "{:url('Admins/upload')}"
            ,before: function(obj){
              //预读本地文件示例，不支持ie8
              obj.preview(function(index, file, result){
                $('#demo1').attr('src', result); //图片链接（base64）
              });
            }
            ,done: function(res){
              //如果上传失败
              if(res.code == 0){
                return top.layer.msg('上传失败',{shade:0.5});
              }else if(res.code){
                //上传成功
                photo = "/public/static/admin/uploads/headphoto/"+res.photo;
                return top.layer.msg('上传成功',{shade:0.5});
              }
            }
            ,error: function(){
              //演示失败状态，并实现重传
              var demoText = $('#demoText');
              demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
              demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
              });
            }
          });

          //显示本地图片
          $("#selffile").click(function () {
            $.post("{:url('Base/getmyfiles')}",{path:"/public/static/admin/uploads/headphoto"},function(data){
              console.log(data);
              var str = "";
              for( i in data.msg){
                str += "<li><img src='/public/static/admin/uploads/headphoto/"+data.msg[i]+"' class='imglist' onclick='changecss(this)' alt=''></li>";
              }
              $("#imglist").html(str);
              //页面层
              layer.open({
                type: 1,
                skin: false, //加上边框
                title: "已上传的图片",
                area: ['700px', '600px'], //宽高
                btn:["确认","取消"],
                content: $(".layer_notive"),  //调到新增页面
                yes:function(){
                  var newImgsrc = $(".active").attr("src");
                  $('#demo1').attr('src', newImgsrc); //图片链接（base64）
                  $('#demo1').attr('width','100%');
                  photo = newImgsrc;
                  layer.closeAll();
                }
              });
            });
          });

        });
          //点击图片选择图片
          function changecss(obj){
            $(".imglist").removeClass("active");
            $(obj).addClass("active");
          }

    </script>
    
    

</body>

</html>
